<template>
	<div class="left-box">
		<div class="heade-wrapper">
			<a-input-search
				class="last-input-box"
				:placeholder="this.$i18n(switchI8nCommand)"
				v-model.trim="searchValue"
				@search="searchHandle"
			/>
		</div>
		<div class="content-wrapper">
			<scroll-list
				panel="OrgRecent"
				:command="switchCommand"
				:iconType="switchIconFont"
				ref="scrollList"
				:initSearchValue="initSearchValue"
				:otherProps="otherProps"
				:titleProps="titleProps"
			/>
		</div>
	</div>
</template>

<script>
import scrollList from '@/components/scrollList';

export default {
	name: 'OrgRecent',
	components: { scrollList },
	inject: ['app'],
	data() {
		return {
			initSearchValue: {},
			searchValue: '',
			// otherProps: ['deptName'],
			titleProps: { code: this.$i18n('org.member_form.code') }
		};
	},
	watch: {},
	computed: {
		orgSelect() {
			return this.app().orgSelect;
		},
		otherProps() {
			return this.onSetOtherProps(['deptName']);
		},
		switchIconFont() {
			const selectType = this.orgSelect && this.orgSelect.selectType;
			if (selectType.includes('Member')) {
				return '';
			}
			if (selectType.includes('Account')) {
				return 'cap-icon-alternative-company';
			}
			if (selectType.includes('Department')) {
				return 'cap-icon-alternative-department';
			}
			return '';
		},
		switchCommand() {
			const selectType = this.orgSelect && this.orgSelect.selectType;
			if (selectType.includes('Member')) {
				return 'memberList';
			}
			if (selectType.includes('Account')) {
				return 'accountList';
			}
			if (selectType.includes('Department')) {
				return 'departmentList';
			}
			return 'memberList';
		},
		switchI8nCommand() {
			const selectType = this.orgSelect && this.orgSelect.selectType;
			if (selectType.includes('Member')) {
				return 'org.index.input.label.js';
			}
			if (selectType.includes('Account')) {
				return 'org.index.input.label.account';
			}
			if (selectType.includes('Department')) {
				return 'org.index.input.label.department';
			}
			return 'org.index.input.label.js';
		}
	},
	beforeMount() {
		this.initSearchValue = {
			accessFileSecretLevel: this.app().orgSelect.accessFileSecretLevel
		};
	},
	mounted() {
	},
	activated() {
		this.searchHandle();
	},
	methods: {
		searchHandle() {
			let { accessFileSecretLevel } = this.orgSelect;
			this.$refs.scrollList.search({
				keyword: this.searchValue,
				accessFileSecretLevel
			});
		},
		/**
		 * 人员【密级】展示处理
		 * @param {Array} list 默认展示的人员信息
		*/
		onSetOtherProps(list) {
			if (this.orgSelect.showSecretLevel) {
				list.unshift('secretLevel')
			}
			return list
		}
	}
};
</script>

<style lang="scss" scoped>
</style>
